/*
 * @Author: xiaosihan 
 * @Date: 2024-08-28 23:04:14 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-08-29 09:41:06
 */



import { AmbientLight, DirectionalLight, PointLight, Vector3 } from "three";
import ThreeBase from "three-base";
import MeshParticles from "./MeshParticles";
import threeUtils from "three-base/threeUtils";
import { degToRad } from "three/src/math/MathUtils";
import meshParticlesJSON from "./meshParticles.json";

/**
 * @class MeshParticlesRender
 * @extends {ThreeBase}
 */
class MeshParticlesRender extends ThreeBase {

    constructor() {
        super();
    }

    // 环境光
    ambientLight = (() => {
        const ambientLight = new AmbientLight("#fff", 3);
        this.scene.add(ambientLight);
        return ambientLight;
    })();

    //点光源
    pointLight = (() => {
        const pointLight = new PointLight("#fff", 1.5);
        pointLight.position.set(50, 40, 50);
        this.scene.add(pointLight);
        return pointLight;
    })();

    // 方向光
    directionalLight = (() => {
        const directionalLight = new DirectionalLight("#fff", 1.5);
        directionalLight.position.set(-10, 10, 5);
        directionalLight.target.position.set(0, 0, 0);
        directionalLight.castShadow = true;
        directionalLight.shadow.mapSize.set(1024, 1024);
        this.scene.add(directionalLight);
        return directionalLight;
    })();

    init() {
        super.init();
        // this.axesHelper.visible = false;
        // this.gridHelper.visible = false;
        // this.controls.enableZoom = false;
        // this.controls.enablePan = false;

        this.resetLookAt({
            center: new Vector3(0, 0, 0),
            position: new Vector3(0, 0, 4)
        });

    }

    //模型粒子
    meshParticles = (() => {
        const meshParticles = new MeshParticles("./model/su7.glb");
        meshParticles.setPointsData(meshParticlesJSON);
        meshParticles.mesh.addEventListener("loaded", () => {
            meshParticles.mesh.rotation.set(0, degToRad(180), 0);
            threeUtils.center(meshParticles.mesh);
            meshParticles.pointMatril.v3size = threeUtils.getSize(meshParticles.mesh);
            meshParticles.mesh.getWorldPosition(meshParticles.pointMatril.center);
        });
        this.add(meshParticles);
        return meshParticles;
    })();


}

const meshParticlesRender = window.meshParticlesRender = new MeshParticlesRender();

export default meshParticlesRender;